﻿using PLCS.App.Shared.Extensions;
using PLCS.Domain.Shared.Logs;
using System.Collections.ObjectModel;

namespace PLCS.App.LogManager.Service;

public static class DataConvertFactory
{
    public static IDataConvert CreateInstance(InterfaceDataType dataType)
    {
        switch (dataType)
        {
            case InterfaceDataType.Json:
                return new JsonDataConvert();

            case InterfaceDataType.Xml:
                return new XmlDataConvert();

            default:
                return null!;
        }
    }

    public static ObservableCollection<PropertyNodeItem> DataConvert(InterfaceDataType dataType, string data)
    {
        IDataConvert dataConvert = CreateInstance(dataType);
        return dataConvert.GetTreeModels(data).ToObservable();
    }
}